<template xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="110px">


      <el-row>
        <el-col :span="12">
          <el-form-item label="商品名称" >
            {{form.goodsName}}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="SKU编码" >
            {{form.skuId}}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="商品价格" >
            {{goodsSku.price}} /元
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商品库存" >
            {{goodsSku.quantity}} /件
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="结算价格" prop="settlementPrice">
            <el-input
              type="number"
              placeholder="请输入结算价格"
              v-model="form.settlementPrice"
              min="1"
              max="100"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="活动库存" prop="stock">
            <el-input
              type="number"
              placeholder="请输入活动库存"
              v-model="form.stock"
              min="1"
              max="1000000"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="最低可砍" prop="lowestPrice">
            <el-input
              type="number"
              placeholder="请输入最低可砍"
              v-model="form.lowestPrice"
              min="1"
              max="100"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最高可砍" prop="highestPrice">
            <el-input
              type="number"
              placeholder="请输入最高可砍"
              v-model="form.highestPrice"
              min="1"
              max="1000000"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="活动时间" >
        <el-date-picker
          v-model="formDateRange"
          type="daterange"
          value-format="yyyy-MM-dd HH:mm:ss"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import {  getKanjiaGoods,updateKanjiaGoods } from "@/api/mall/promotion/kanjia-goods";
export default {
  name: "KanJiaGoodsEdit",
  dicts: ['mall_promotion_state'],
  props: {
    activityId: {
      type: String
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      // 表单参数
      form: {
        freeFreightFlag: 1
      },
      goodsSku: {},
      formDateRange: [],
      // 表单校验
      rules: {
        rangeTime: [{ required: true, message: "请选择优惠券有效期" ,trigger: "blur"}],
      },
    };
  },
  created() {
    this._getKanjiaGoods();
  },
  methods: {
    /** 查询商城满减活动详情 */
    _getKanjiaGoods() {
      getKanjiaGoods(this.activityId).then(response => {
        this.form = response.data.activityGoods;
        this.formDateRange = []
        this.formDateRange[0] = this.form.startTime
        this.formDateRange[1] = this.form.endTime
        this.goodsSku = response.data.goodsSku
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.formDateRange.length < 1){
            this.$modal.msgError("请选择活动时间");
            return
          }else{
            this.form.startTime = this.formDateRange[0]
            this.form.endTime = this.formDateRange[1]
          }
          this.form.promotionGoodsList = this.promotionGoodsList
          updateKanjiaGoods(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.$emit('emitUpdateEdit')
          });
        }
      });
    },
    cancel() {
      this.$emit('emitUpdateEdit')
    }
  }
};
</script>
